 package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import Models.POSLoyaltyPoints;

public class POSLoyaltyPointsPresenter extends AbstractPresenter<POSLoyaltyPoints> {
	final String SINGLEITEM = "posLoyaltyPoints";
	final String MULTIITEM = "posLoyaltyPointss";
	
	public ArrayList<POSLoyaltyPoints> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public POSLoyaltyPoints tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public POSLoyaltyPoints createItemFromJSONObject(JSONObject jsonLoyaltyPoint){
		POSLoyaltyPoints loyaltyPoint = new POSLoyaltyPoints();
		try{
			loyaltyPoint.setId(jsonLoyaltyPoint.getInt("lpID"));
			loyaltyPoint.setDescription(jsonLoyaltyPoint.getString("lpDescription"));
			loyaltyPoint.setPoints(jsonLoyaltyPoint.getInt("lpPoints"));
			loyaltyPoint.setValue(jsonLoyaltyPoint.getDouble("lpValue"));
			return loyaltyPoint;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(POSLoyaltyPoints item){
		try{
			JSONObject json = new JSONObject();
			json.put("lpDescription", item.getDescription());
			json.put("lpID", item.getId());
			json.put("lpPoints", item.getPoints());
			json.put("lpValue", item.getValue());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public POSLoyaltyPoints getEmptyEntity(){
		POSLoyaltyPoints entity = new POSLoyaltyPoints();
		return entity;
	}
}
